import { Component, OnInit } from '@angular/core';
import { Validators, FormBuilder } from '@angular/forms';
import { AuthService } from 'src/app/shared/services/auth.service';

@Component({
  selector: 'app-register',
  templateUrl: './register.component.html',
  styleUrls: ['./register.component.less']
})
export class RegisterComponent implements OnInit {
  registerForm = this.fb.group({
    account: ['', Validators.required],
    password: ['', Validators.required],
    checkpwd: ['', Validators.required],
    email: ['', Validators.required]
  });
  constructor(private authService: AuthService, private fb: FormBuilder) {}
  ngOnInit(): void {}
  onSubmit() {
    const { account, password, checkpwd, email } = this.registerForm.value;
    if (password === checkpwd) {
      this.authService.register({
        account,
        password,
        email
      });
    } else {
      alert('两次密码不一致');
    }
  }
}
